package com.ctg.payroll2.dao.payment.impl;

import java.sql.SQLException;
import java.util.List;

import com.ctg.payroll2.bean.filter.payment.PayDataFilter;
import com.ctg.payroll2.bean.po.payment.PayData;
import com.ctg.payroll2.bean.po.payment.PayEmpdata;
import com.ctg.payroll2.bean.po.payment.PayInput;
import com.ctg.payroll2.dao.payment.PayEmpdataDao;
import com.ctg.platform.orm.ibatis.IbatisEntityDao;
import com.ctg.platform.util.Page;

@SuppressWarnings("unchecked")
public class PayEmpdataDaoImpl extends IbatisEntityDao implements PayEmpdataDao {

	public List<PayData> queryPayDataList(PayDataFilter filter) throws Exception {
		return getSqlMapClient().queryForList(getNameSpace() + ".queryPayData_query", filter);
	}

	public Page queryPayTotal(PayDataFilter filter) {
		return pagedQueryByFilter(this.getClass(), filter,
				".queryPayTotal_count",
				".queryPayTotal_query");
	}
	
	public List<PayEmpdata> queryPayClassEmpList(PayDataFilter filter) throws SQLException {
		return getSqlMapClient().queryForList(getNameSpace() + ".getPayEmpDataByFilter", filter);
	}

	/**
	 * 批量新增员工薪资档案
	 * @param list 员工薪资档案list
	 */
	public void insertPayEmpdata(List<PayEmpdata> list){
		try {
			getSqlMapClient().startBatch();
			for (PayEmpdata empdata : list) {
				getSqlMapClient().insert(getNameSpace() + ".insertPayEmpdata", empdata);
			}
			getSqlMapClient().executeBatch();
		}catch(SQLException e){
			e.printStackTrace();
		}
	}
	/**
	 * 更新员工薪资档案
	 * @param empdata 员工薪资档案对象
	 * @return
	 */
	public int updatePayEmpData(PayEmpdata empdata){
		int i = 0;
		try {
			i = getSqlMapClient().update(getNameSpace() + ".updatePayEmpData", empdata);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return i;
	}
	/**
	 * 根据id删除员工薪资档案
	 * @param id 员工薪资档案id
	 */
	public void deletePayEmpDataSingle(Long id){
		try {
			getSqlMapClient().delete(getNameSpace() + ".deletePayEmpDataSingle", id);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 根据以逗号分隔的员工薪资档案id批量删除
	 * @param ids 以逗号分隔的员工薪资档案i
	 */
	public void deletePayEmpDataBatch(String ids){
		try {
			getSqlMapClient().delete(getNameSpace() + ".deletePayEmpDataBatch", ids);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public List<PayInput> queryPayInput(PayInput filter) throws SQLException{
		return getSqlMapClient().queryForList(getNameSpace() + ".queryPayInput", filter);
	}
	
	public void insertCsPayInput(PayInput payInput) throws SQLException{
		getSqlMapClient().insert(getNameSpace() + ".insertCsPayInputThis", payInput);
		getSqlMapClient().insert(getNameSpace() + ".insertCsPayInputNext", payInput);
	}
	
	public void updateCsPayInput(PayInput payInput) throws SQLException{
		getSqlMapClient().update(getNameSpace() + ".updateCsPayInputThis", payInput);
		getSqlMapClient().update(getNameSpace() + ".updateCsPayInputNext", payInput);
	}
	
	private String getNameSpace(){
		return this.getClass().getSimpleName();
	}
}
